package com.zzptc.ly.bookcity.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.zzptc.ly.bookcity.Bean.CollectionItem;
import com.zzptc.ly.bookcity.R;

import java.util.List;

public class CollectionAdapter extends ArrayAdapter<CollectionItem> {
    int resourceid;
    public CollectionAdapter(@NonNull Context context, int resource, @NonNull List<CollectionItem> objects) {
        super(context, resource, objects);
        this.resourceid=resource;
    }
    @Override
    public View getView(int position, View converView, ViewGroup parent){
        View view=converView;
        if (view==null){
            view= LayoutInflater.from(getContext()).inflate(resourceid,null);
        }
        ImageView bookimg=view.findViewById(R.id.bookimg);
        TextView bookname=view.findViewById(R.id.bookname);
        TextView authornamr=view.findViewById(R.id.authorname);
        ImageView iscollected=view.findViewById(R.id.iscollected);

        CollectionItem c=getItem(position);
        bookimg.setImageResource(c.getBookimg());
        bookname.setText(c.getBookname());
        authornamr.setText(c.getAuthorname());

        if (c.isIscollected()){
            iscollected.setImageResource(R.mipmap.shixin);
        }else{
            iscollected.setImageResource(R.mipmap.kongxin);
        }
        return view;
    }

}
